﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Bidder_CompanyGMPList : System.Web.UI.Page
{
    public string strConditions, AccountId, Isshow="block"; 

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                AccountId = SysFun.ToTrim(_Account.AccountId);
               
                System.Data.IDataReader dr;
                //取得该企业的名称

                string strSql = "select isnull(checkstatus,0) as checkstatus from company where Accountid='" + _Account.AccountId.ToString() + "'";
                Db db = new Db();
                dr = db.DataReader(strSql);
                while (dr.Read())
                {
                    if (dr["checkstatus"].ToString().Equals("1") || dr["checkstatus"].ToString().Equals("3")) Isshow = "none";
                    else Isshow = "block";
                }
                dr.Close();
                db.Close();
                if (Request.Form["btnSubmit"] == "删除" && Request.Form["chk"] != null)
                {
                    string delGMPId = Request.Form["chk"].ToString();
                     strSql = "delete from companygmp where [id] in (" + delGMPId + ") and accountid=" + AccountId;
                    db = new Db();
                    db.Command(strSql);
                    db.Close();
                }
               
                showGridView();
            }
            else
            {
                Response.Write("<script>alert('您还没有登录，请登录后再修改！！');location.href='../HomePage/Default.aspx'</script>");

            }
        }

    }
    protected void Button5_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 数据绑定
    /// </summary>
    public void showGridView()
    {
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "COMPANY INNER JOIN COMPANYGMP ON COMPANY.ACCOUNTID=COMPANYGMP.ACCOUNTID";                                               //要查询的表明
        dbPage.Key = " COMPANYGMP.[ID]";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = " COMPANYGMP.[ID],COMPANY.ACCOUNTID,COMPANY.COMPANYNAME,COMPANY.USERCODE,COMPANYGMP.GMPCODE,COMPANYGMP.GMPSTARDATE,COMPANYGMP.GMPENDDATE,COMPANYGMP.GMPRANGE";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "COMPANYGMP.GMPCODE";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlAttorney.DataSource = dr;
        DlAttorney.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键




    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", GMPCODE = "", GMPRANGE;

        strtemp = " COMPANYGMP.AccountId=" + AccountId +" and";
        GMPCODE = txtGMPCODE.Text.ToString();
        GMPRANGE = txtGMPRANGE.Text.ToString();
        if (GMPRANGE != "")
        {
            strtemp = strtemp + " COMPANYGMP.GMPRANGE like '%" + GMPRANGE + "%' and";
        }
        if (GMPCODE != "")
        {
            strtemp = strtemp + " COMPANYGMP.GMPCODE like '%" + GMPCODE + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;
    }

}
